package com.ruoyi.InventoryInfo.service.impl;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import com.ruoyi.InventoryInfo.domain.InventoryInbound;
import com.ruoyi.common.core.domain.R;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.InventoryInfo.mapper.InventoryInfoMapper;
import com.ruoyi.InventoryInfo.domain.InventoryInfo;
import com.ruoyi.InventoryInfo.service.IInventoryInfoService;

/**
 * 存货信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-03-12
 */
@Service
public class InventoryInfoServiceImpl implements IInventoryInfoService 
{
    @Autowired
    private InventoryInfoMapper inventoryInfoMapper;

    /**
     * 查询存货信息
     * 
     * @param id 存货信息主键
     * @return 存货信息
     */
    @Override
    public InventoryInfo selectInventoryInfoById(Long id)
    {
        return inventoryInfoMapper.selectInventoryInfoById(id);
    }

    /**
     * 查询存货信息列表
     * 
     * @param inventoryInfo 存货信息
     * @return 存货信息
     */
    @Override
    public List<InventoryInfo> selectInventoryInfoList(InventoryInfo inventoryInfo)
    {
        return inventoryInfoMapper.selectInventoryInfoList(inventoryInfo);
    }

    /**
     * 新增存货信息
     * 
     * @param inventoryInfo 存货信息
     * @return 结果
     */
    @Override
    public int insertInventoryInfo(InventoryInfo inventoryInfo)
    {
        System.out.println(inventoryInfo);
        InventoryInbound inventoryInbound = new InventoryInbound();
        inventoryInbound.setDocumentNo(inventoryInfo.getInventoryCode());
        inventoryInbound.setDocumentDate(new Date());
        inventoryInbound.setInboundType("采货入库");
        inventoryInbound.setWarehouseName("自动一体化仓库");
        inventoryInbound.setInboundQuantity(inventoryInfo.getCurrentStock());
        Double totalCost = inventoryInfo.getPurchasePrice().doubleValue() * inventoryInfo.getCurrentStock();
        inventoryInbound.setTotalCost(BigDecimal.valueOf(totalCost));
        inventoryInbound.setSupplier("自动一体化供应商");
        inventoryInbound.setProject("自动一体化项目");
        inventoryInbound.setDepartment("自动一体化部门");
        inventoryInbound.setHandler("自动一体化人员");
        inventoryInbound.setDocumentTime(new Date());
        inventoryInbound.setDocumentMaker("张三");
        inventoryInfoMapper.insertInventoryInbound(inventoryInbound);
        return inventoryInfoMapper.insertInventoryInfo(inventoryInfo);
    }

    /**
     * 修改存货信息
     * 
     * @param inventoryInfo 存货信息
     * @return 结果
     */
    @Override
    public int updateInventoryInfo(InventoryInfo inventoryInfo)
    {
        return inventoryInfoMapper.updateInventoryInfo(inventoryInfo);
    }

    /**
     * 批量删除存货信息
     * 
     * @param ids 需要删除的存货信息主键
     * @return 结果
     */
    @Override
    public int deleteInventoryInfoByIds(Long[] ids)
    {
        return inventoryInfoMapper.deleteInventoryInfoByIds(ids);
    }

    /**
     * 删除存货信息信息
     * 
     * @param id 存货信息主键
     * @return 结果
     */
    @Override
    public int deleteInventoryInfoById(Long id)
    {
        return inventoryInfoMapper.deleteInventoryInfoById(id);
    }


}
